package com.chookss.tiku;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.base.BaseViewHolderEx;
import com.google.gson.reflect.TypeToken;
import com.chookss.R;
import com.chookss.Urls;
import com.chookss.tiku.entity.AnswerResultEntity;
import com.chookss.tiku.util.TiKuUtils;
import com.chookss.tools.ClearMoreZeroUtil;
import com.chookss.tools.GridSpacingItemDecoration;
import com.chookss.tools.MyToast;
import com.chookss.tools.SignUtils2;
import com.chookss.tools.Utils;
import com.chookss.tools.okgoconfig.MyHttpRequest;
import com.chookss.tools.okgoconfig.callback.ObserverCallback;
import com.chookss.tools.okgoconfig.model.LzyResponse;
import com.chookss.view.LianxiDialog;
import com.chookss.view.RecycleViewDivider;
import com.chookss.view.listener.ShareDialogListener;
import com.johnrambo.ktea.common.klogutil.KLog;
import com.lvgroup.hospital.base.BaseAct;

import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

//答题结果页
public class ExamResultActivitys extends BaseAct {

    @BindView(R.id.common_title_txt)
    TextView commonTitleTxt;
    @BindView(R.id.common_right_txt)
    TextView commonRightTxt;
    @BindView(R.id.common_title_rel)
    RelativeLayout commonTitleRel;
    @BindView(R.id.tvDate)
    TextView tvDate;
    @BindView(R.id.tvScoreInit1)
    TextView tvScoreInit1;
    @BindView(R.id.tvScore)
    TextView tvScore;
    @BindView(R.id.tvScoreInit2)
    TextView tvScoreInit2;
    @BindView(R.id.tvAverage)
    TextView tvAverage;
    @BindView(R.id.tvAverageInit)
    TextView tvAverageInit;
    @BindView(R.id.llScore)
    LinearLayout llScore;
    @BindView(R.id.llThree)
    LinearLayout llThree;
    @BindView(R.id.llScore2)
    LinearLayout llScore2;
    @BindView(R.id.tvPractice)
    TextView tvPractice;
    @BindView(R.id.tvPracticeNum)
    TextView tvPracticeNum;
    @BindView(R.id.tvPracticeInit)
    TextView tvPracticeInit;
    @BindView(R.id.tvTime)
    TextView tvTime;
    @BindView(R.id.tvRank)
    TextView tvRank;
    @BindView(R.id.tvRankInit)
    TextView tvRankInit;
    @BindView(R.id.knowledgeRcv)
    RecyclerView knowledgeRcv;
    @BindView(R.id.llAnswer)
    LinearLayout llAnswer;
    @BindView(R.id.llBg)
    LinearLayout llBg;
    @BindView(R.id.llBackProblem)
    LinearLayout llBackProblem;
    @BindView(R.id.tvResult1)
    TextView tvResult1;
    @BindView(R.id.ivNotAnswer)
    ImageView ivNotAnswer;
    @BindView(R.id.tvNotAnswer)
    TextView tvNotAnswer;
    @BindView(R.id.rcvResult1)
    RecyclerView rcvResult1;
    @BindView(R.id.llResult1)
    LinearLayout llResult1;
    @BindView(R.id.tvResult2)
    TextView tvResult2;
    @BindView(R.id.rcvResult2)
    RecyclerView rcvResult2;
    @BindView(R.id.llResult2)
    LinearLayout llResult2;
    @BindView(R.id.tvResult3)
    TextView tvResult3;
    @BindView(R.id.rcvResult3)
    RecyclerView rcvResult3;
    @BindView(R.id.llResult3)
    LinearLayout llResult3;
    @BindView(R.id.tvResult4)
    TextView tvResult4;
    @BindView(R.id.rcvResult4)
    RecyclerView rcvResult4;
    @BindView(R.id.llResult4)
    LinearLayout llResult4;
    @BindView(R.id.tvResult5)
    TextView tvResult5;
    @BindView(R.id.rcvResult5)
    RecyclerView rcvResult5;
    @BindView(R.id.llResult5)
    LinearLayout llResult5;
    @BindView(R.id.tvBottom)
    TextView tvBottom;
    private String recordType = "1";//1 智能练习 2 专项练习 3 模拟 4 正式 5 背题
    private int isMiss = 0;// 是否缺考 0否 1是
    private String pmKey, examCode, examName;
    private KnowledgeAdapter knowledgeAdapter;
    private DetailAdapter singleAdapter, checkboxAdapter, judgeAdapter,adapter4,adapter5;
    private List<AnswerResultEntity.KnowMainBean> knowMainBeanList = new ArrayList<>();
    private List<AnswerResultEntity.SubjectSheetBean> checkboxSubjectList = new ArrayList<>();
    private List<AnswerResultEntity.SubjectSheetBean> singleSubjectList = new ArrayList<>();
    private List<AnswerResultEntity.SubjectSheetBean> judgeSubjectList = new ArrayList<>();
    private List<AnswerResultEntity.SubjectSheetBean> list4 = new ArrayList<>();
    private List<AnswerResultEntity.SubjectSheetBean> list5 = new ArrayList<>();
    private AnswerResultEntity.RecordBean recordBean;
    private int interval = 0;
    private int type = 0;//0是默认情况 1是从模拟卷和考试过来的  2智能练习或者专项练习顶部进来的点击右上角直接关闭

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_exam_results);
        ButterKnife.bind(this);

    }

    @Override
    public void initData() {
        initState();
        type = getIntent().getIntExtra("type", 0);
        isMiss = getIntent().getIntExtra("isMiss", 0);
        recordType = getIntent().getStringExtra("recordType");
        pmKey = getIntent().getStringExtra("pmKey");
        examCode = getIntent().getStringExtra("examCode");
        examName = getIntent().getStringExtra("examName");
        interval = (Utils.getScreenWidthPixel(this) - Utils.dip2px(this, 266F)) / 7;

        Drawable drawableRight = ContextCompat.getDrawable(this, R.drawable.icon_z_wenh);
        drawableRight.setBounds(0, 0, Utils.dip2px(this, 13), Utils.dip2px(this, 13));
        ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) llBg.getLayoutParams();
        if ("5".equals(recordType)) {
            commonRightTxt.setText("去答题");
            params.height = Utils.dip2px(this, 121);
            llBg.setLayoutParams(params);
            llScore.setVisibility(View.GONE);
            llBackProblem.setVisibility(View.VISIBLE);
            llAnswer.setVisibility(View.GONE);
            commonTitleTxt.setText("今日成果-背题模式");
            tvPracticeInit.setText("背题数量");
            tvRankInit.setText("排名");
            tvPracticeInit.setCompoundDrawables(null, null, drawableRight, null);
            tvPracticeInit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    new LianxiDialog(ExamResultActivitys.this, "背题数量为在满足背题时长基础上用户当天所背题目数量总和。其中不同记忆阶段的题目所需背题时长不等，且练习模式下的题目及记忆曲线处于“已牢记”阶段的题目均不计入当天背题数量。").show();
                }
            });
        } else {
            params.height = 743 * Utils.getScreenWidthPixels(this) / 828;
            llBg.setLayoutParams(params);
            KLog.i(Utils.getScreenWidthPixels(this)+"==="+(743 * Utils.getScreenWidthPixels(this) / 828));
            llBg.setBackgroundResource(R.drawable.zqv_bg);
            LinearLayout.LayoutParams params0= (LinearLayout.LayoutParams) tvDate.getLayoutParams();
            params0.setMargins(Utils.dip2px(this,12),Utils.dip2px(this,15),0,0);
            tvDate.setLayoutParams(params0);
            LinearLayout.LayoutParams params1= (LinearLayout.LayoutParams) llScore.getLayoutParams();
            params1.setMargins(0,Utils.dip2px(this,54),0,0);
            llScore.setLayoutParams(params1);
            LinearLayout.LayoutParams params2= (LinearLayout.LayoutParams) llScore2.getLayoutParams();
            params2.setMargins(0,Utils.dip2px(this,12),0,0);
            llScore2.setLayoutParams(params2);
            LinearLayout.LayoutParams params22= (LinearLayout.LayoutParams) tvAverage.getLayoutParams();
            params22.setMargins(0,Utils.dip2px(this,6),0,0);
            tvAverage.setLayoutParams(params22);
            LinearLayout.LayoutParams params3= (LinearLayout.LayoutParams) tvAverageInit.getLayoutParams();
            params3.setMargins(0,Utils.dip2px(this,47),0,0);
            tvAverageInit.setLayoutParams(params3);
            LinearLayout.LayoutParams params4= (LinearLayout.LayoutParams) llThree.getLayoutParams();
            params4.setMargins(0,Utils.dip2px(this,35),0,0);
            llThree.setLayoutParams(params4);
            llScore.setVisibility(View.VISIBLE);
            llBackProblem.setVisibility(View.GONE);
            llAnswer.setVisibility(View.VISIBLE);
            if ("1".equals(recordType)) {
                commonRightTxt.setText("去答题");
                commonTitleTxt.setText("今日成果-智能练习");
                tvScoreInit1.setText("正确率");
                tvScoreInit2.setText("%");
                tvAverageInit.setText("我的正确率VS平均正确率");
                tvPracticeInit.setText("练习数量");
                tvRankInit.setText("有效排名");
                tvRankInit.setCompoundDrawables(null, null, drawableRight, null);
                ivNotAnswer.setVisibility(View.GONE);
                tvNotAnswer.setVisibility(View.GONE);
            } else if ("2".equals(recordType)) {
                commonRightTxt.setText("去答题");
                commonTitleTxt.setText("今日成果-专项练习");
                tvScoreInit1.setText("正确率");
                tvScoreInit2.setText("%");
                tvAverageInit.setText("我的正确率VS平均正确率");
                tvPracticeInit.setText("练习数量");
                tvRankInit.setText("有效排名");
                tvRankInit.setCompoundDrawables(null, null, drawableRight, null);
                ivNotAnswer.setVisibility(View.GONE);
                tvNotAnswer.setVisibility(View.GONE);
            } else if ("3".equals(recordType)) {
                commonRightTxt.setText("重新练习");
                commonTitleTxt.setText(examName);
                tvScoreInit1.setText("得分");
                tvScoreInit2.setText("分");
                tvAverageInit.setText("我的成绩VS平均成绩");
                tvPracticeInit.setText("答对题数");
                tvRankInit.setText("考试排名");
            } else if ("4".equals(recordType)) {
                commonTitleTxt.setText(examName);
                tvScoreInit1.setText("得分");
                tvScoreInit2.setText("分");
                tvAverageInit.setText("我的成绩VS平均成绩");
                tvPracticeInit.setText("答对题数");
                tvRankInit.setText("考试排名");
            }
        }
        if (type == 0) {
            commonRightTxt.setVisibility(View.VISIBLE);
            commonRightTxt.setTextColor(this.getResources().getColor(R.color.main_color));
        } else if (type == 1) {
            commonRightTxt.setVisibility(View.GONE);
            tvBottom.setText("全部解析");
        }else if (type == 2) {
            commonRightTxt.setVisibility(View.GONE);
            tvBottom.setText("去答题");
        }

        knowledgeRcv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        knowledgeRcv.addItemDecoration(new RecycleViewDivider(
                this, LinearLayoutManager.HORIZONTAL, Utils.dip2px(this, 0.5f), getResources().getColor(R.color.line_gray)
        ));
        knowledgeAdapter = new KnowledgeAdapter(R.layout.item_examresult_knowledge, this, knowMainBeanList);
        knowledgeRcv.setAdapter(knowledgeAdapter);
        GridLayoutManager gridLayoutManager = new GridLayoutManager(this, 7);
        GridSpacingItemDecoration gridSpacingItemDecoration = new GridSpacingItemDecoration(7, interval, false);
        GridLayoutManager gridLayoutManager2 = new GridLayoutManager(this, 7);
        GridSpacingItemDecoration gridSpacingItemDecoration2 = new GridSpacingItemDecoration(7, interval, false);
        GridLayoutManager gridLayoutManager3 = new GridLayoutManager(this, 7);
        GridSpacingItemDecoration gridSpacingItemDecoration3 = new GridSpacingItemDecoration(7, interval, false);
        GridLayoutManager gridLayoutManager4 = new GridLayoutManager(this, 7);
        GridSpacingItemDecoration gridSpacingItemDecoration4 = new GridSpacingItemDecoration(7, interval, false);
        GridLayoutManager gridLayoutManager5 = new GridLayoutManager(this, 7);
        GridSpacingItemDecoration gridSpacingItemDecoration5 = new GridSpacingItemDecoration(7, interval, false);
        rcvResult1.addItemDecoration(gridSpacingItemDecoration);
        rcvResult1.setLayoutManager(gridLayoutManager);
        singleAdapter = new DetailAdapter(R.layout.item_examresult_detail, this, singleSubjectList, 0);
        rcvResult1.setAdapter(singleAdapter);
        rcvResult2.addItemDecoration(gridSpacingItemDecoration2);
        rcvResult2.setLayoutManager(gridLayoutManager2);
        checkboxAdapter = new DetailAdapter(R.layout.item_examresult_detail, this, checkboxSubjectList, 1);
        rcvResult2.setAdapter(checkboxAdapter);
        rcvResult3.addItemDecoration(gridSpacingItemDecoration3);
        rcvResult3.setLayoutManager(gridLayoutManager3);
        judgeAdapter = new DetailAdapter(R.layout.item_examresult_detail, this, judgeSubjectList, 2);
        rcvResult3.setAdapter(judgeAdapter);
        rcvResult4.addItemDecoration(gridSpacingItemDecoration4);
        rcvResult4.setLayoutManager(gridLayoutManager4);
        adapter4 = new DetailAdapter(R.layout.item_examresult_detail, this, list4, 2);
        rcvResult4.setAdapter(adapter4);
        rcvResult5.addItemDecoration(gridSpacingItemDecoration5);
        rcvResult5.setLayoutManager(gridLayoutManager5);
        adapter5 = new DetailAdapter(R.layout.item_examresult_detail, this, list5, 2);
        rcvResult5.setAdapter(adapter5);
        rcvResult1.setPadding(0, 0, 0, interval);
        rcvResult2.setPadding(0, 0, 0, interval);
        rcvResult3.setPadding(0, 0, 0, interval);
        rcvResult4.setPadding(0, 0, 0, interval);
        rcvResult5.setPadding(0, 0, 0, interval);
        tvRankInit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("1".equals(recordType) || "2".equals(recordType)) {
                    new LianxiDialog(ExamResultActivitys.this, "有效排名为根据员工岗位要求的学习范围及记忆曲线上升情况综合排名").show();
                }
            }
        });
        getData();
    }

    private void getData() {
        Map<String, String> map = new HashMap<>();
        map.put("pmKey", pmKey);
        map.put("recordType", recordType);
        map.put("isMiss", isMiss + "");
        showLoading();
        MyHttpRequest.getDefault().postRequest(new TypeToken<LzyResponse<AnswerResultEntity>>() {
        }.getType(), null, Urls.getRecordDetail, SignUtils2.makeSignStr(map), false, new ObserverCallback<AnswerResultEntity>() {
            @Override
            public void onSuccess(AnswerResultEntity data) {
                dismissLoading();
                if(tvDate==null){
                    return;
                }
                recordBean = data.getRecord();
                tvDate.setText("答题时间：" + data.getRecord().getCreateTime());
                tvTime.setText(data.getRecord().getTimeLength());
                tvRank.setText(data.getRecord().getRank());
                if ("1".equals(recordType)) {
                    tvScore.setText(ClearMoreZeroUtil.subZeroAndDot(data.getRecord().getRightRatio()));
                    tvAverage.setText("平均正确率" + Utils.changeNumber(data.getRecord().getJudgeRatio()) + "%");
                    tvPractice.setText(data.getRecord().getTotalNum());
                } else if ("2".equals(recordType)) {
                    tvScore.setText(ClearMoreZeroUtil.subZeroAndDot(data.getRecord().getRightRatio()));
                    tvAverage.setText("平均正确率" + Utils.changeNumber(data.getRecord().getJudgeRatio()) + "%");
                    tvPractice.setText(data.getRecord().getTotalNum());
                } else if ("3".equals(recordType)) {
                    tvScore.setText(ClearMoreZeroUtil.subZeroAndDot(data.getRecord().getScore()));
                    tvAverage.setText("平均成绩" + ClearMoreZeroUtil.subZeroAndDot(data.getRecord().getAverageValue()) + "分");
                    tvPractice.setText((Utils.changeNumber(data.getRecord().getJudgeRightNum()) + Utils.changeNumber(data.getRecord().getCheckboxRightNum()) + Utils.changeNumber(data.getRecord().getSingleRightNum()) + Utils.changeNumber(data.getRecord().getFillRightNum()) + Utils.changeNumber(data.getRecord().getAskRightNum())) + "");
                    tvPracticeNum.setText("/" + data.getRecord().getTotalNum() + "道");
                } else if ("4".equals(recordType)) {
                    tvScore.setText(ClearMoreZeroUtil.subZeroAndDot(data.getRecord().getScore()));
                    tvAverage.setText("平均成绩" + ClearMoreZeroUtil.subZeroAndDot(data.getRecord().getAverageValue()) + "分");
                    tvPractice.setText((Utils.changeNumber(data.getRecord().getJudgeRightNum()) + Utils.changeNumber(data.getRecord().getCheckboxRightNum()) + Utils.changeNumber(data.getRecord().getSingleRightNum()) + Utils.changeNumber(data.getRecord().getFillRightNum()) + Utils.changeNumber(data.getRecord().getAskRightNum())) + "");
                    tvPracticeNum.setText("/" + data.getRecord().getTotalNum() + "道");
                } else {
                    tvPractice.setText(data.getRecord().getTotalNum());
                }
                knowMainBeanList.addAll(data.getKnowMain());
                knowledgeAdapter.notifyDataSetChanged();
                List<AnswerResultEntity.SubjectSheetBean> list = data.getSubjectSheet();
                //1001 选择题//1002 多选题//1003 判断题
                int singleInt = 0, checkboxInt = 0, judgeInt = 0,cnt1004=0,cnt1005=0;
                for (int i = 0; i < list.size(); i++) {
                    if ("1001".equals(list.get(i).getSubjectTypeCode())) {
                        singleSubjectList.add(list.get(i));
                        if ("1".equals(list.get(i).getIsValid())) {
                            singleInt++;
                        }
                    } else if ("1002".equals(list.get(i).getSubjectTypeCode())) {
                        checkboxSubjectList.add(list.get(i));
                        if ("1".equals(list.get(i).getIsValid())) {
                            checkboxInt++;
                        }
                    } else if ("1003".equals(list.get(i).getSubjectTypeCode())) {
                        judgeSubjectList.add(list.get(i));
                        if ("1".equals(list.get(i).getIsValid())) {
                            judgeInt++;
                        }
                    }else if ("1004".equals(list.get(i).getSubjectTypeCode())) {
                        list4.add(list.get(i));
                        if ("1".equals(list.get(i).getIsValid())) {
                            cnt1004++;
                        }
                    }else if ("1005".equals(list.get(i).getSubjectTypeCode())) {
                        list5.add(list.get(i));
                        if ("1".equals(list.get(i).getIsValid())) {
                            cnt1005++;
                        }
                    }
                }
                if (singleSubjectList.size() > 0) {
                    llResult1.setVisibility(View.VISIBLE);
                    int num = Utils.changeNumber(data.getRecord().getSingleRightNum()) + Utils.changeNumber(data.getRecord().getSingleErrorNum());
                    if ("5".equals(recordType)) {
                        tvResult1.setText("单选题(" + singleInt + "/" + singleSubjectList.size() + ")");
                    } else {
                        tvResult1.setText("单选题(" + Utils.changeNumber(data.getRecord().getSingleRightNum()) + "/" + num + ")");

                    }
                    singleAdapter.notifyDataSetChanged();
                }
                if (checkboxSubjectList.size() > 0) {
                    llResult2.setVisibility(View.VISIBLE);
                    int num = Utils.changeNumber(data.getRecord().getCheckboxRightNum()) + Utils.changeNumber(data.getRecord().getCheckboxErrorNum());
                    if ("5".equals(recordType)) {
                        tvResult2.setText("多选题(" + checkboxInt + "/" + checkboxSubjectList.size() + ")");
                    } else {
                        tvResult2.setText("多选题(" + Utils.changeNumber(data.getRecord().getCheckboxRightNum()) + "/" + num + ")");

                    }
                    checkboxAdapter.notifyDataSetChanged();
                }
                if (judgeSubjectList.size() > 0) {
                    llResult3.setVisibility(View.VISIBLE);
                    int num = Utils.changeNumber(data.getRecord().getJudgeRightNum()) + Utils.changeNumber(data.getRecord().getJudgeErrorNum());
                    if ("5".equals(recordType)) {
                        tvResult3.setText("判断题(" + judgeInt + "/" + judgeSubjectList.size() + ")");
                    } else {
                        tvResult3.setText("判断题(" + Utils.changeNumber(data.getRecord().getJudgeRightNum()) + "/" + num + ")");

                    }
                    judgeAdapter.notifyDataSetChanged();
                }
                if (list4.size() > 0) {
                    llResult4.setVisibility(View.VISIBLE);
                    int num = Utils.changeNumber(data.getRecord().getFillRightNum()) + Utils.changeNumber(data.getRecord().getFillErrorNum());
                    if ("5".equals(recordType)) {
                        tvResult4.setText("填空题(" + cnt1004 + "/" + list4.size() + ")");
                    } else {
                        tvResult4.setText("填空题(" + Utils.changeNumber(data.getRecord().getFillRightNum()) + "/" + num + ")");

                    }
                    adapter4.notifyDataSetChanged();
                }
                if (list5.size() > 0) {
                    llResult5.setVisibility(View.VISIBLE);
                    int num = Utils.changeNumber(data.getRecord().getAskRightNum()) + Utils.changeNumber(data.getRecord().getAskErrorNum());
                    if ("5".equals(recordType)) {
                        tvResult5.setText("问答题(" + cnt1005 + "/" + list5.size() + ")");
                    } else {
                        tvResult5.setText("问答题(" + Utils.changeNumber(data.getRecord().getAskRightNum()) + "/" + num + ")");

                    }
                    adapter5.notifyDataSetChanged();
                }
                if (data.getSubjectSheet().size() == 0) {
                    new LianxiDialog(ExamResultActivitys.this, "结果正在计算中，请稍后", new ShareDialogListener() {
                        @Override
                        public void onClick() {
                            finish();
                        }
                    }).show();
                }
            }

            @Override
            public void onError(String errorMsg) {
                dismissLoading();
                MyToast.show(Utils.onErrorTips(errorMsg));
            }
        });
    }

    class KnowledgeAdapter extends BaseQuickAdapter<AnswerResultEntity.KnowMainBean, BaseViewHolder> {
        private Context context;

        public KnowledgeAdapter(int layoutResId, Context context, @io.reactivex.annotations.Nullable List<AnswerResultEntity.KnowMainBean> data) {
            super(layoutResId, data);
            this.context = context;
        }

        @Override
        protected void convert(BaseViewHolder helper, AnswerResultEntity.KnowMainBean item) {
            TextView tvName = helper.getView(R.id.tvName);
            TextView tvNum = helper.getView(R.id.tvNum);
            tvName.setText(item.getCatalogName());
            tvNum.setText("共" + item.getTotalNum() + "道");
        }

    }

    class DetailAdapter extends BaseQuickAdapter<AnswerResultEntity.SubjectSheetBean, BaseViewHolderEx> {
        private Context context;
        private int type = 0;//0单选1多选2 判断

        public DetailAdapter(int layoutResId, Context context, @io.reactivex.annotations.Nullable List<AnswerResultEntity.SubjectSheetBean> data, int type) {
            super(layoutResId, data);
            this.context = context;
        }

        @Override
        protected void convert(BaseViewHolderEx helper, AnswerResultEntity.SubjectSheetBean item) {
            TextView tv = helper.getView(R.id.tv);
            tv.setText((helper.getItemPosition() + 1) + "");
            if ("5".equals(recordType)) {
                //是否有效，等做到背题模式要验证
                if ("1".equals(item.getIsValid())) {
                    tv.setTextColor(Color.parseColor("#11B3FF"));
                    tv.setBackgroundResource(R.drawable.shape_circle_11b3ff);
                } else {
                    tv.setTextColor(Color.parseColor("#333333"));
                    tv.setBackgroundResource(R.drawable.shape_circle_f7f7f7_cc);
                }
            } else {
                if (Utils.isNull(item.getOptionLvlNo())) {
                    tv.setTextColor(Color.parseColor("#333333"));
                    tv.setBackgroundResource(R.drawable.shape_circle_white);
                } else if ("1".equals(item.getIsRight())) {
                    tv.setTextColor(Color.parseColor("#44D3B3"));
                    tv.setBackgroundResource(R.drawable.shape_circle_44d3b3);
                } else if ("0".equals(item.getIsRight())) {
                    tv.setTextColor(Color.parseColor("#F2434D"));
                    tv.setBackgroundResource(R.drawable.shape_circle_e43d1c);
                } else {
                    tv.setTextColor(Color.parseColor("#333333"));
                    tv.setBackgroundResource(R.drawable.shape_circle_white);
                }
            }
        }

    }

    @RequiresApi(api = Build.VERSION_CODES.N)
    @OnClick({R.id.common_title_back, R.id.common_title_rel, R.id.tvBottom})
    public void onClick(View view) {
        Intent intent = null;
        switch (view.getId()) {
            case R.id.common_title_back:
                finish();
                break;
            case R.id.common_title_rel:
                if ("1".equals(recordType)) {
                    if (type == 2) {
                        finish();
                        return;
                    }
                    intent = new Intent(this, PracticeTestActivity.class);
                    intent.putExtra("practiceType", "1");
                    startActivity(intent);
                } else if ("2".equals(recordType)) {
                    if (type == 2) {
                        finish();
                        return;
                    }
                    intent = new Intent(this, SelectPracticeCatalog.class);
                    startActivity(intent);
                } else if ("3".equals(recordType)) {
                    intent = new Intent(this, SelectSimulationCatalog.class);
                    startActivity(intent);
                } else if ("4".equals(recordType)) {
                    //考试没有任何跳转
                    if(commonRightTxt==null){
                        return;
                    }
                    if(Utils.isNull(commonRightTxt.getText().toString())){
                        return;
                    }
                } else {
                    if (type == 2) {
                        finish();
                        return;
                    }
                    intent = new Intent(this, PracticeTestActivity.class);
                    intent.putExtra("practiceType", "1");
                    startActivity(intent);
                }
                finish();
                break;
            case R.id.tvBottom:
                if(tvTime==null){
                    return;
                }
                if (type == 0||type == 1) {
                    if(recordType.equals("3")||recordType.equals("4")){
                        if(recordBean==null){
                            return;
                        }
                        if(Utils.isNull(recordBean.getExamCode())){
                            return;
                        }
                    }else{
                        if(Utils.isNull(pmKey)){
                            return;
                        }
                    }
                    intent = new Intent(this, ExamRecordSubjectListActivity.class);
                    intent.putExtra("examCode", recordBean.getExamCode());
                    intent.putExtra("practiceType", recordType);
                    intent.putExtra("isMiss", isMiss + "");
                    intent.putExtra("periodName", recordBean.getCreateTime());
                    intent.putExtra("recordUid", pmKey);
                    intent.putExtra("time", tvTime.getText().toString());
                    if (recordType.equals("1") || recordType.equals("2")) {
                        intent.putExtra("title", TiKuUtils.recordTypeName(recordType));
                    } else {
                        intent.putExtra("title", commonTitleTxt.getText().toString());
                    }
                    startActivity(intent);
                } else if(type==2){
                    finish();
                }
                break;
        }
    }
}
